<?php

namespace App\Jobs;

use Carbon\Carbon;
use App\Models\Group;
use App\Services\FinishGroup\FinishGroup;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use App\Services\CloseUnpaidProductOrder\CloseUnpaidProductOrder;


class CloseGroupJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    
    protected $group;
    
    public function __construct(Group $group)
    {
    	$this->group = $group;
        //
    	$this->delay(Carbon::now()->addDays(cs('sale')->group_expired));
    }
	
	public function handle()
    {
         app(FinishGroup::class, [
            'group' => $this->group
        ])->finishByJob();
    }
}
